package com.lucker.controller.push;


import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lucker.controller.BaseController;
import com.lucker.framework.constant.ResponseBaseModel;
import com.lucker.service.push.socket.SocketService;
import com.lucker.vo.CaiOpenInfo;


@Controller
@RequestMapping(value = "push")
public class PushController extends BaseController {
	@Autowired
	SocketService  socketService;
	

	@RequestMapping(value="/pushall",method = RequestMethod.GET)
	public @ResponseBody ResponseEntity<?> commit_opencode(HttpServletRequest req , CaiOpenInfo info) {
		
		try {
			socketService.sendKeepalivedMessage();
			return new ResponseEntity<>(new ResponseBaseModel(10000,"ok"), HttpStatus.OK);
		}catch(Exception e) {
			this.getLoger().error("登录异常 {} , {}", e.getMessage(),e);
			return new ResponseEntity<>(new ResponseBaseModel(29002,e.getMessage()), HttpStatus.OK);
		}
		
	}
	
	
	@RequestMapping(value="/init",method = RequestMethod.GET)
	public @ResponseBody ResponseEntity<?> init_socket(HttpServletRequest req , CaiOpenInfo info) {
		
		try {
			socketService.initSocketListener();
			return new ResponseEntity<>(new ResponseBaseModel(10000,"ok"), HttpStatus.OK);
		}catch(Exception e) {
			this.getLoger().error("SOCKET初始化异常 {} , {}", e.getMessage(),e);
			return new ResponseEntity<>(new ResponseBaseModel(29002,e.getMessage()), HttpStatus.OK);
		}
		
	}
}
